





var _oMessages =
{
sNoSelectedEntity:		LOCID_ENTLST_MUSTSELECT,
sTooManyEntities:		LOCID_ENTLST_TOOMANY,
sExportEntityWarning:	LOCID_EXPORT_WARNING,
sCannotUpdateNonEntity:	LOCID_ENTLST_CANTUPDNONENT
};





var _oConst =
{

custom:							"custom",
publishable:					"publishable",
entityFilter:					"entityFilter",
exportFilter:					"exportFilter",


sCreateEntityUrl:				"manageEntity.aspx",
sUpdateEntityUrlFormat:			"/Tools/SystemCustomization/Entities/manageEntity.aspx?entityId={0}",
sDeleteAction:					"delete",
sUpdateAction:					"update",
sUpdateIconsAction:				"updateicons",
sExportAction:					"export",
sPublishAction:					"publish",
iEntityEditorWidth:				800,
iEntityEditorHeight:			600
};





function EntityListJsWindowOnLoad()
{
gridEntities.OnBeforeFormLoad = onEntityDblClick;
if(gridEntities.GetParameter("isActionExportCustomization")!= "1")
{


gridEntities.SetParameter("disableDblClick", "0");
}
else
{

gridEntities.SetParameter("disableDblClick", "1");
}
if (typeof(selFilter) != "undefined")
{
if (selFilter.DefaultValue != selFilter.value)
{
selFilter.value = selFilter.DefaultValue;
}
}
}
window.attachEvent('onload', EntityListJsWindowOnLoad);








function CallbackParams(bClose, bReload, bRefreshGrid)
{
this.bClose			= bClose;
this.bReload		= bReload;
this.bRefreshGrid	= bRefreshGrid;
}



function dispatchAction(aEntityList, iMaxRecords, sAction)
{

if (aEntityList == null)
{
alert(_oMessages.sNoSelectedEntity);
return;
}


if (iMaxRecords != 0 && aEntityList.length > iMaxRecords)
{
alert(_oMessages.sTooManyEntities);
return;
}

switch (sAction)
{
case _oConst.sDeleteAction:
deleteEntityAction(aEntityList[0][0]);
break;

case _oConst.sUpdateAction:
updateEntityAction(aEntityList[0][0]);
break;

case _oConst.sUpdateIconsAction:
updateEntityIconsAction(aEntityList[0][0]);
break;
case _oConst.sExportAction:
exportEntityAction(aEntityList);
break;
case _oConst.sPublishAction:
publishEntityAction(aEntityList);
break;
}
}



function remoteEntityCommandCallback(oResult)
{
if (oResult.Success &&
oResult.RemoteCommand.Command == _oEntUtlConst.sDeleteEntityCommand &&
!IsNull(oResult.ReturnValue) &&
oResult.ReturnValue.Used)
{
showUsage(_oSCUConst.sEntityMode, oResult.ReturnValue);
}
else
{
gridEntities.Refresh();
}
return true;
}



function createEntityAction()
{

openStdWin(_oConst.sCreateEntityUrl, buildWinName(), _oConst.iEntityEditorWidth, _oConst.iEntityEditorHeight);
}



function updateEntityAction(sEntityOid)
{

var sEntityId	= getEntityId(sEntityOid);
if (sEntityId == null)
{
alert(_oMessages.sCannotUpdateNonEntity);
return;
}

var sUrl = prependOrgName(formatString(_oConst.sUpdateEntityUrlFormat, sEntityId));
openStdWin(sUrl, buildWinName(sEntityId), _oConst.iEntityEditorWidth, _oConst.iEntityEditorHeight);
}



function deleteEntityAction(sEntityOid)
{
var sEntityId		= getEntityId(sEntityOid);
var bCustomEntity	= (getEntityType(sEntityOid) == _oConst.custom);
deleteEntity(sEntityId, bCustomEntity, remoteEntityCommandCallback);
}



function updateEntityIconsAction(sEntityOid)
{
var sEntityId		= getEntityId(sEntityOid);
var bCustomEntity	= (getEntityType(sEntityOid) == _oConst.custom);
updateEntityIcons(sEntityId, bCustomEntity);

gridEntities.document.location.reload(false);
}



function exportEntityAction(aEntityList)
{

var aAllEntities = getAllEntities()
if (aAllEntities.length != aEntityList.length)
{
alert(_oMessages.sExportEntityWarning);
}



var exportListXml = "<importexportxml>";
var entityId;
for (var i = 0; i < aEntityList.length; i++)
{
entityId = getEntityId(aEntityList[i][0]);
if (entityId != null)
{
var entityType = getEntityType(aEntityList[i][0]);
switch (entityType)
{
case "securityrole":
exportListXml += "<securityrole>" + entityId + "</securityrole>";
break;
case "workflow":
exportListXml += "<workflow>" + entityId + "</workflow>";
break;
case "setting":
exportListXml += "<setting>" + entityId + "</setting>";
break;
case "node":
exportListXml += "<node>" + entityId + "</node>";
break;
default:
exportListXml += "<entity>" + entityId + "</entity>";
break;
}
}
}
exportListXml += "</importexportxml>";

exportForm.exportListXml.value = exportListXml;
exportForm.submit();
}



function publishEntityAction(aEntityList)
{
var sEntity;
var bPublishableEntity = 1;
var oDataXml = createXmlDoc(_oTags.publish);
var oEntitiesXml = addXmlNode(oDataXml, _oTags.entities);
for (var i = 0; i < aEntityList.length; i++)
{
sEntityId = getEntityId(aEntityList[i][0]);
bPublishableEntity = bPublishableEntity
& (getEntityType(aEntityList[i][0]) == _oConst.publishable
|| getEntityType(aEntityList[i][0]) == _oConst.custom);
addTextXmlNode(oEntitiesXml, _oTags.entity, sEntityId);
}

var sDataXml = convertXmlDocToString(oDataXml);
var oCallbackParams = new CallbackParams(false, false, false);

publishEntities(sDataXml, bPublishableEntity, remoteEntityCommandCallback, oCallbackParams);
}
function publishAllEntities()
{
var oCallbackParams = new CallbackParams(false, false, false);
publishEntitiesAll(remoteEntityCommandCallback, oCallbackParams);
}








function onFilterChange()
{
gridEntities.SetParameter(_oConst.entityFilter, selFilter.DataValue);
gridEntities.SetParameter(_oConst.exportFilter, "All");
gridEntities.Refresh();
}



function onExportFilterChange()
{
gridEntities.SetParameter(_oConst.entityFilter, "Exportable");
gridEntities.SetParameter(_oConst.exportFilter, selectFilter.DataValue);
gridEntities.Refresh();
}



function onEntityDblClick()
{
updateEntityAction(event.ObjectID);
event.returnValue = false;
}










function getAllEntities()
{
return gridEntities.InnerGrid.AllRecords;
}
function getSelectedEntities()
{
var aRecords = gridEntities.InnerGrid.SelectedRecords;
return (aRecords.length > 0) ? aRecords : null;
}



function getEntityType(sEntityOid)
{
return sEntityOid.split(":")[0];
}



function getEntityId(sEntityOid)
{
return sEntityOid.split(":")[1];
}
